package com.xy.home.service.impl;
import com.ruoyi.common.core.mapper.home.HomeOrdersMapper;
import com.xy.home.service.OrderHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页订单统计服务实现类
 */
@Service
public class OrderHomeServiceImpl implements OrderHomeService {

    @Autowired
    private HomeOrdersMapper orderHomeMapper;

    /**
     * 获取订单统计数据
     * @return
     */
    @Override
    public Map<String, Object> selectOrdersCount() {
        Map<String, Object> result = new HashMap<>();
        // 获取总订单数
        Long total = orderHomeMapper.selectTotalOrders();
        // 获取今日订单数
        Long today = orderHomeMapper.selectTodayOrders();

        result.put("total", total);
        result.put("today", today);
        return result;
    }

    /**
     * 获取订单状态统计数据
     * @param status 订单状态
     * @return
     */
    @Override
    public Map<String, Object> selectOrdersCountByStatus(Long status) {
        Map<String, Object> result = new HashMap<>();
        // 获取指定状态的总订单数
        Long total = orderHomeMapper.selectTotalOrdersByStatus(status);
        // 获取指定状态的今日订单数
        Long today = orderHomeMapper.selectTodayOrdersByStatus(status);

        result.put("total", total);
        result.put("today", today);
        return result;
    }

    /**
     * 获取指定状态的订单数
     * @return
     */
    @Override
    public Map<String, Object> selectTotalSales() {
        Map<String, Object> result = new HashMap<>();
        // 获取总销售额
        Double total = orderHomeMapper.selectTotalSalesAmount();
        // 获取今日销售额
        Double today = orderHomeMapper.selectTodaySalesAmount();

        result.put("total", total);
        result.put("today", today);
        return result;
    }

    /**
     * 获取月度订单数据
     * @return
     */
    @Override
    public List<Map<String, Object>> selectMonthlyOrdersData() {
        return orderHomeMapper.selectMonthlyOrders();
    }

    /**
     * 获取最近七天订单数据
     * @return
     */
    @Override
    public List<Map<String, Object>> selectRecentDailyOrders() {
        return orderHomeMapper.selectRecentDailyOrders();
    }

    /**
     * 获取支付方式分布
     * @return
     */
    @Override
    public List<Map<String, Object>> selectPaymentMethodDistribution() {
        return orderHomeMapper.selectPaymentMethodDistribution();
    }
}